//
//  AvtivityController.m
//  电影er
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AvtivityController.h"
#import "AvtivityModel.h"
#import "AvtiTableViewCell.h"
#import "AvitiSendController.h"
#import "Hight.h"
@interface AvtivityController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,retain)NSMutableArray *muarray;

@end

@implementation AvtivityController
-(void)dealloc{
    [_muarray release];
    [super dealloc];
}
- (void)viewDidLoad {
    
    self.muarray = [[NSMutableArray alloc]init];
    
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTabbar];
    [self number];
    [self ucreaTabview];
    
}
-(void)creatTabbar{
    self.navigationItem.title = @"活动";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.41f green:0.61f blue:0.68f alpha:1.00f];
    self.navigationController.navigationBar.titleTextAttributes=@{
                                                                  NSForegroundColorAttributeName:[UIColor blackColor],
                                                                  NSFontAttributeName:[UIFont boldSystemFontOfSize:20]
                                                                  
                                                                  };
    
    self.automaticallyAdjustsScrollViewInsets =NO;
    
}

-(void)ucreaTabview{
    
    UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height -64) style:UITableViewStylePlain];
    tableview.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:tableview];
    
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.rowHeight = 200;
    
    [tableview registerClass:[AvtiTableViewCell class] forCellReuseIdentifier:@"cell"];
    
}
-(void)number{
    
    NSString *str =[[NSBundle mainBundle]pathForResource:@"activitylist" ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:str];
    NSError *error =nil;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
    NSArray *array  = [dic objectForKey:@"events"];
    
    for (NSDictionary *dict  in array) {
        AvtivityModel *model = [[AvtivityModel alloc]init];
        [model setValuesForKeysWithDictionary:dict];
        [self.muarray addObject:model];
        [model release];
        
        
    }
    
       
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.muarray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AvtiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    AvtivityModel *mode = [self.muarray objectAtIndex:indexPath.row];
    cell.model = mode;
    return cell;
    
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    AvtivityModel *mode = [self.muarray objectAtIndex:indexPath.row];
    
    return [Hight heightWith:mode.title]+220;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AvitiSendController *asvc = [[AvitiSendController alloc]init];
    self.avtmodel = [self.muarray objectAtIndex:indexPath.row];
    asvc.asmodel = self.avtmodel;
    
    [self.navigationController pushViewController:asvc animated:YES];
    
    
}









@end
